<template>
  <h1>循环指令</h1>
  <ul>
    <li v-for="item in 3">{{ item }}</li>
  </ul>
  <ul>
    <li v-for="item in productArr">{{ item }}</li>
  </ul>
  <table border="1px">
    <tr>
      <th>序号</th>
      <th>商品名称</th>
      <th>商品价格</th>
      <th>商品库存</th>
      <th>操作</th>
    </tr>
    <tr v-for="(p,index) in productArr">
      <td>{{ index + 1 }}</td>
      <td>{{ p.title }}</td>
      <td>{{ p.price }}</td>
      <td>{{ p.num }}</td>
      <td>
        <button @click="del(index)">删除</button>
      </td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

let productArr = ref([
  {title: '小米14', price: 3999, num: 600},
  {title: 'iPone16', price: 8999, num: 800},
  {title: 'IQOO13', price: 4999, num: 300},
  {title: 'IQOO13', price: 4999, num: 300},
  {title: 'IQOO13', price: 4999, num: 300},
  {title: 'IQOO13', price: 4999, num: 300},
  {title: '华为Mate70', price: 6999, num: 0}
]);

const del = (index) => {
  if (confirm('您确认要删除本商品吗?')) {
    productArr.value.splice(index, 1);
  }
}
</script>

<style scoped>

</style>